#include "ICamera.h"

ICamera::ICamera(void)
{
}

ICamera::~ICamera(void)
{
}

void ICamera::Init()
{
	mPosition = Vector3<float>(0,0,0);
	mForward = Vector3<float>(0,0,-1);
	mLeft = Vector3<float>(1,0,0);
	mUp = Vector3<float>(0,1,0);
	mRotation = Vector3<float>(0,0,0);

	mViewChanged = true;
}

void ICamera::Update(void)
{
}

Vector3<float> ICamera::GetPosition()
{
	return mPosition;
}

void ICamera::SetPosition(Vector3<float> position)
{
	mPosition = position;
}
void ICamera::SetPosition(float x, float y, float z)
{
	mPosition.x = x;
	mPosition.y = y;
	mPosition.z = z;
}

Vector3<float> ICamera::GetRotation()
{
	return mRotation;
}

void ICamera::SetRotation(Vector3<float> rotation)
{
	mRotation = rotation;
}
void ICamera::SetRotation(float x, float y, float z)
{
	mRotation.x = x;
	mRotation.y = y;
	mRotation.z = z;

	mViewChanged = true;
}

Vector3<float> ICamera::GetForward()
{
	return mForward;
}

Vector3<float> ICamera::GetLeft()
{
	return mLeft;
}

Vector3<float> ICamera::GetUp()
{
	return mUp;
}

void ICamera::MoveForward(float distance)
{
	CheckViewChangedAndUpdate();

	mPosition = mPosition + mForward * distance;
}
void ICamera::StrafeLeft(float distance)
{
	CheckViewChangedAndUpdate();

	mPosition = mPosition + mLeft * distance;
}

// roation abt x axis
void ICamera::RotateX(float angle)
{
	mRotation.x += angle;
}

// roation abt y axis
void ICamera::RotateY(float angle)
{
	mRotation.y += angle;
}

void ICamera::CheckViewChangedAndUpdate()
{
	if(mViewChanged)
	{
		Vector3<float> Step1, Step2;
		//Rotate around Y-axis:
		Step1.x = (float)cos( (mRotation.y - 90.0) * PIdiv180);
		Step1.z = (float)-sin( (mRotation.y - 90.0) * PIdiv180);
		//Rotate around X-axis:
		float cosX = cos (mRotation.x * PIdiv180);
		Step2.x = (float)Step1.x * cosX;
		Step2.z = (float)Step1.z * cosX;
		Step2.y = (float)sin(mRotation.x * PIdiv180);
		//Rotation around Z-axis not yet implemented, so:
		mForward = Step2;
		mLeft.x = mForward.z;
		mLeft.y = mForward.y;
		mLeft.z = mForward.x;
	}
	mViewChanged = false;
}



